<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8" />
  <title></title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <link href="/static/css/font.css?v={{data.version}}" rel="stylesheet">
  <link href="/static/css/weadmin.css?v={{data.version}}" rel="stylesheet">
</head>

<body>
  <div class="weadmin-nav">
    <span class="layui-breadcrumb">
      <a href="javascript:;">首页</a> <a href="javascript:;">系统</a>
      <a href="javascript:;"> <cite>访问权限</cite></a>
    </span>
    <a class="layui-btn layui-btn-sm" style="margin-top:3px;float:right"
      href="javascript:location.replace(location.href);" title="刷新">
      <i class="layui-icon layui-icon-refresh"></i>
    </a>
  </div>

  <div class="weadmin-body">
    <form class="layui-form">

      <div class="layui-form-item">
        <label for="L_username" class="layui-form-label">
          <span class="we-red">*</span>域名配置
        </label>
        <div class="layui-input-inline">
          <textarea id="nginx_domain" name="nginx_domain" class="layui-textarea"></textarea>
        </div>

        <div style="line-height: 38px;">前台访问</div>
      </div>

      <div class="layui-form-item">
        <label for="L_username" class="layui-form-label">
          <span class="we-red">*</span>访问域名
        </label>
        <div class="layui-input-inline">
          <textarea id="nginx_domain_acl" name="nginx_domain_acl" class="layui-textarea"></textarea>
        </div>

        <div style="line-height: 38px;">权限访问域名[空,所有都可以访问]</div>
      </div>

      <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">
          <span class="we-red">*</span>配置文件
        </label>
        <div class="layui-input-inline">
          <input type="text" name="nginx_path" class="layui-input">
        </div>

        <div style="line-height: 38px;">(配置文件位置)</div>
      </div>

      <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">
          <span class="we-red">*</span>nginx[WWW]
        </label>
        <div class="layui-input-inline">
          <input type="text" name="nginx_www" class="layui-input">
        </div>

        <div style="line-height: 38px;">(www路径)</div>
      </div>

      <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">
          <span class="we-red">*</span>nginx[Video]
        </label>
        <div class="layui-input-inline">
          <input type="text" name="nginx_video_www" class="layui-input">
        </div>

        <div style="line-height: 38px;">(www video 路径)</div>
      </div>


      <div class="layui-form-item">
        <label for="L_username" class="layui-form-label">
          <span class="we-red">*</span>开启监控
        </label>
        <div class="layui-input-inline">
          <input type="checkbox" name="nginx_listen" lay-skin="switch" lay-text="ON|OFF" lay-filter="switchTest" value="1">
            <div class="layui-unselect layui-form-switch" lay-skin="_switch">
              <em>OFF</em><i></i>
            </div>
        </div>
      </div>

      <div class="layui-form-item">
        <label for="L_repass" class="layui-form-label">
        </label>
        <button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
      </div>
    </form>
  </div>
  <script src="/static/lib/layui/layui.js" charset="utf-8"></script>

  <script>

    layui.extend({
      base: '/static/js/'
      , version: '1011001'
    });
    layui.use(['form', 'jquery', 'util', 'layer'], function () {
      var form = layui.form,
        $ = layui.jquery,
        util = layui.util,
        admin = layui.admin,
        layer = layui.layer;

      $.getJSON('/system_api/getConf',{}, function(data){
        // console.log(data);
        if (data['code'] == 0){
            var list = {};
            for (var v in data['data']) {
              var key = data['data'][v]['name'];
              var value = data['data'][v]['value'];
              list[key] = value;
            }
            $("textarea[name='nginx_domain']").val(list['nginx_domain']);
            $("textarea[name='nginx_domain_acl']").val(list['nginx_domain_acl']);
            $("input[name='nginx_path']").val(list['nginx_path']);
            $("input[name='nginx_www']").val(list['nginx_www']);
            $("input[name='nginx_video_www']").val(list['nginx_video_www']);

            if (list['nginx_listen'] == '1'){
              $(".layui-form-switch").addClass('layui-form-onswitch');
              $(".layui-form-switch").find('em').text('ON');
            }
            $("checkbox[name='nginx_listen']").val(list['nginx_path']);
            form.render('select');
        } else {
            layer.msg(data.msg);
        }
      });

      //监听提交
      form.on('submit(add)', function (data) {
        var f = data.field;
        console.log(f);
        $.post('/system_api/editConf',f,function(data){
            console.log(data,f);
            data = $.parseJSON(data);
            layer.msg(data.msg);
            setTimeout(function(){
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                window.parent.window.location.reload();
            },2000);
        });
        return false;
      });

    });
  </script>
</body>

</html>